package gov.kqqzyyy.monkey.clinicscreen.network;

import java.util.List;
import java.util.concurrent.TimeUnit;

import gov.kqqzyyy.monkey.clinicscreen.network.bean.BaseResponse;
import gov.kqqzyyy.monkey.clinicscreen.network.config.HttpConfig;
import gov.kqqzyyy.monkey.clinicscreen.objects.CallPatient_New;
import gov.kqqzyyy.monkey.clinicscreen.objects.ClinicArea_New;
import gov.kqqzyyy.monkey.clinicscreen.objects.ClinicDoctor_New;
import gov.kqqzyyy.monkey.clinicscreen.objects.ClinicPatient;
import gov.kqqzyyy.monkey.clinicscreen.objects.WarnInfo;
import io.reactivex.Observable;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;


public class RetrofitUtil {

    private static RetrofitUtil mRetrofitUtil;
    private final ApiInterface mApiInterface;

    private RetrofitUtil() {
        OkHttpClient mOkHttpClient = new OkHttpClient.Builder()
                .connectTimeout(HttpConfig.CONNECT_TIMEOUT, TimeUnit.SECONDS)
                .readTimeout(HttpConfig.READ_TIMEOUT, TimeUnit.SECONDS)
                .writeTimeout(HttpConfig.WRITE_TIMEOUT, TimeUnit.SECONDS)
                .build();
        Retrofit mRetrofit = new Retrofit.Builder()
                .baseUrl(HttpConfig.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())//添加gson转换器
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())//添加rxjava转换器
                .client(mOkHttpClient)
                .build();
        mApiInterface = mRetrofit.create(ApiInterface.class);
    }

    public static RetrofitUtil getInstence() {
        if (mRetrofitUtil == null) {
            synchronized (RetrofitUtil.class) {
                if (mRetrofitUtil == null)
                    mRetrofitUtil = new RetrofitUtil();
            }

        }
        return mRetrofitUtil;
    }

    public Observable<BaseResponse<WarnInfo>> getClinicWarnInfo(String ctrllerID) {
        return mApiInterface.getClinicWarnInfo(ctrllerID);
    }

    public Observable<BaseResponse<String>> getServerTime() {
        return mApiInterface.getServerTime();
    }


    public Observable<BaseResponse<List<ClinicArea_New>>> getClinicAreas() {
        return mApiInterface.getClinicAreas();
    }

    public Observable<BaseResponse<List<ClinicDoctor_New>>> getClinicDoctors(String ctrllerID) {
        return mApiInterface.getClinicDoctors(ctrllerID);
    }

    public Observable<BaseResponse<List<ClinicPatient>>> getClinicPatients(String ctrllerID) {
        return mApiInterface.getClinicPatients(ctrllerID);
    }

    public Observable<BaseResponse<List<CallPatient_New>>> getCallPatients(String ctrllerID) {
        return mApiInterface.getCallPatients(ctrllerID);
    }

    public Observable<BaseResponse<String>> updateCallPatient(int id) {
        return mApiInterface.updateCallPatient(id);
    }

}
